package cn.tedu.submarine;

import javax.swing.*;



public class Boss extends SeaObject {
    public static final int FIRE_ONE = 0;
    public static final int FIRE_TWO = 1;
    public static final int FIRE_SHREE = 2;
    private int fire = FIRE_ONE;

    public static final int GO_UP = 0;
    public static final int ALEFT = 1;
    public static final int ARIGHT = 2;
    private int kineState = GO_UP;
    private int bossCounter = 0;
    private int bossLeftIndex = 0;//boss左组图下标
    private int bossRightIndex = 0;//boss右组图下标

    public Boss() {
        super(230, 129, 512, 812, 3, World.levelNumber * World.magnification);
        setState(PREPARE);
    }

    public void BossCounter() {
        bossCounter++;
        if (bossCounter == 1000) {
            setState(LIVE);
        }
    }


    @Override
    public void move() {
        if (kineState == GO_UP) {
            setY(getY() - getSpeed());
            if (getY() <= World.HEIGHT - 150) {
                kineState = ALEFT;
            }
        } else if (kineState == ALEFT) {
            setX(getX() - getSpeed());
            if (getX() <= 0) {
                kineState = ARIGHT;
            }
        } else if (kineState == ARIGHT) {
            setX(getX() + getSpeed());
            if (getX() >= World.WIDTH - getWidth()) {
                kineState = ALEFT;
            }
        }
    }


    public BossBomb[] shootBossBo(int fire) {//boss子弹产生方法
        BossBomb[] bb = new BossBomb[0];
        this.fire = fire;
        if (this.fire == FIRE_TWO) {
            bb = new BossBomb[1];
            bb[0] = new BossBomb(128, 128, getX() + getWidth() / 2, getY(), 4, 1,this.fire);
        } else if (this.fire == FIRE_SHREE) {
            bb = new BossBomb[3];
            for (int i = 0; i < bb.length; i++) {
                bb[i] = new BossBomb(60, 64, getX() + getWidth() / 2, getY(), 6, i,this.fire);
            }
        }
        return bb;
    }

    int leftIndex = 0;
    int rightIndex = 0;
    int moIndex = 0;
    int boomIndex = 0;
    public ImageIcon getImage() {
        if (isLive()) {
            if (kineState == GO_UP || kineState == ALEFT) {
                leftIndex++;
                if (leftIndex % 10 == 0) {
                    return Images.bossleft[bossLeftIndex++%6];
                } else {
                    return Images.bossleft[bossLeftIndex%6];
                }
            } else {
                rightIndex++;
                if (rightIndex % 10 == 0) {
                    return Images.bossright[bossRightIndex++%6];
                } else {
                    return Images.bossright[bossRightIndex%6];
                }
            }
        } else{
            if (++moIndex % 10 == 0) {
                boomIndex++;
                if (boomIndex==8){
                    setState(REMOVE);
                    return Images.bossboom[boomIndex-1];
                }
                return Images.bossboom[boomIndex];
            }else {
                return Images.bossboom[boomIndex];
            }
        }

    }
}
